#!/usr/bin/env python
# -*- coding:GBK -*-
#========================================================================
#   FileName: minSocketServer.py
#     Author: linh
#      Email: linh@ecallcen.com
#   HomePage: 
# LastChange: 2012-09-07 23:07:49
#========================================================================
import SocketServer
import sys
class RequestHandler(SocketServer.StreamRequestHandler):
    "Handles one request to mirror some text"

    def handle(self):
        l = True
        print self.client_address
        dataStr="{result_code:'0',err_msg:'',message_name:'imrIReturnTermialInfo',data:[ {nObjectId:'',nTerminalId:'',nState:'',psStaffId:'104'} ]}"
        while l:
            print 'aaaaaaaaaaaa'
            l = self.rfile.readline().strip()
            if l:
                print 'aaaa:'+l
                self.wfile.write(dataStr+ '\n')


if __name__ == '__main__':
    if len(sys.argv) < 3:
        print 'Usage: %s [hostname] [port number]' % sys.argv[0]
        sys.exit(1)
    hostname = sys.argv[1]
    port = int(sys.argv[2])
    print hostname
    print str(port)

    SocketServer.ThreadingTCPServer((hostname,port), RequestHandler).serve_forever()

